package com.review.sort;

public class ShellSort {
    //希尔排序{1,2,3,4,5,6,7,9,10}
    public void shellSort(int[] array) {//与直接插入排序类似，多了一个增量
        for (int n = array.length / 2; n > 0; n /= 2) {//定义增量的变化
            for (int i = n; i < array.length; i += n) {//修改增量变化
                for (int j = i; j >= 0; j-=n) {
                    if (j - n >= 0 && array[j - n] > array[j]) {
                        int tmp = array[j - n];
                        array[j - n] = array[j];
                        array[j] = tmp;
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] ints = {8, 6, 7, 5, 9, 4, 1, 10, 2, 3};
        new ShellSort().shellSort(ints);
        for (int anInt : ints) {
            System.out.print(anInt + ",");
        }
    }
}
